<template>
	<view class="city">
		<navbar title="城市选择"></navbar>
		<view class="p30 bgwhite mt30">
			<view class="top bor-bot acea-row row-middle pb30">
				<view class="vline"></view>
				<view class="themecolor fs30 ml20">可切换的城市</view>
				<view class="ml20 fs30 fc222">当前城市：</view>
				<view class="fs30 fc222 ml10">{{ cityname }}</view>
			</view>
			<view class="">
				<block v-for="(item,index) in list" :key="index">
					<view class="fs30 bold fc222 mt30">{{ item.name }}</view>
					<view class="acea-row">
						<view class="city-item mt30 mr30" v-for="(citem,cindex) in item.child" :key="cindex" @click="open(citem)">
							{{ citem.name }}
						</view>
					</view>
				</block>
			</view>
		</view>
		
		<uni-popup type="center" ref="popup">
			<view class="frame acea-row row-column row-middle row-around">
				<view class="fs36 fc333 bold">温馨提示</view>
				<view class="fs40 fc333 bold mt30">您确定切换{{ city }}吗？</view>
				<view class="acea-row row-between-wrapper mt30">
					<view class="btn bgccc fc9e" @click="close">取消</view>
					<view class="btn fcwhite bgtheme" @click="confrim">确定</view>
				</view>
			</view>
		</uni-popup>
		
	</view>
</template>

<script>
	const app = getApp();
	import{
		provinceList
	} from "@/api/api.js"
	import navbar from '../../components/navbar.vue'
	export default {
		components:{
			navbar
		},
		data() {
			return {
				list:[],
				city:'',
				cityname:"",
			};
		},
		onShow() {
			this.getcity();
			this.cityname = app.globalData.cityname;
		},
		methods:{
			confrim(){
				app.globalData.cityname = this.city;
				this.cityname = this.city;
				this.close();
				uni.navigateBack();
			},
			getcity(){
				provinceList().then(res=>{
					this.list = res.data.data;
				})
			},
			close(){
				this.$refs.popup.close();
			},
			open(item){
				this.city = item.name;
				this.$refs.popup.open();
			}
		}
	}
</script>

<style lang="scss">
	.city{
		
		.city-item{
			width: 140rpx;
			min-height: 68rpx;
			border-radius: 16rpx;
			background: #E8E8E8;
			text-align: center;
			line-height: 68rpx;
			text-align: center;
		}
		
		.frame{
			width: 660rpx;
			height: 380rpx;
			border-radius: 20rpx;
			background: #FFFFFF;
			padding: 30rpx;
			
			.btn{
				width: 240rpx;
				height: 70rpx;
				border-radius: 35rpx;
				text-align: center;
				line-height: 70rpx;
				margin: 0 20rpx;
				font-size: 28rpx;
			}
		}
		
	}
</style>
